import java.util.*;

class SetGeneric<T>
{
    private ArrayList<T> elements;
    
    public SetGeneric(int max_size)
    {
        elements = new ArrayList<T>(max_size);
    }
    
    public SetGeneric()
    {
        elements = new ArrayList<T>();
    }
    
    public boolean add(T el)
    {
        if (is_in_set(el))
        {
            return false;
        }
        
        elements.add(el);
        return true;
    }
    
    public boolean is_in_set(T el)
    {
        for (T element : elements)
        {
            if (element.equals(el))
            {
                return true;
            }
        }
        
        return false;
    }
    
    public String toString()
    {
        String s = "set: [";
        for (T el : elements)
        {
            s += el + ",";
        }
        s += "]";
        return s;
    }
    
    public void print()
    {
        System.out.println(toString());
    }
    
    public void clear()
    {
        elements.clear();
    }

    public int size()
    {
        return elements.size();
    }
    
    public boolean is_empty()
    {
        return elements.isEmpty();
    }
}

public class SetGenericTest
{
    public static void main(String[] args)
    {
        SetGeneric<String> s = new SetGeneric<String>(5);
        
        System.out.println("test SetGeneric");
        System.out.println("========");

        System.out.println(String.format("is_empty(): %b", s.is_empty()));
        System.out.println(String.format("size(): %d", s.size()));
        System.out.println(String.format("add(\"string1\"): %b", s.add("string1")));
        System.out.println(String.format("is_empty(): %b", s.is_empty()));
        System.out.println(String.format("add(\"string2\"): %b", s.add("string2")));
        System.out.println(String.format("add(\"string5\"): %b", s.add("string5")));
        s.print();
        System.out.println(String.format("size(): %d", s.size()));
        System.out.println(String.format("add(\"string5): %b", s.add("string5")));
        System.out.println(String.format("add(\"string6\"): %b", s.add("string6")));
        System.out.println(String.format("size(): %d", s.size()));
        System.out.println(String.format("add(\"string7\"): %b", s.add("string7")));
        System.out.println(String.format("size(): %d", s.size()));
        System.out.println(String.format("add(\"string8\"): %b", s.add("string8")));
        System.out.println(String.format("size(): %d", s.size()));
        s.print();
        System.out.println(String.format("is_in_set(\"string5\"): %b", s.is_in_set("string5")));
        System.out.println(String.format("is_in_set(\"string8\"): %b", s.is_in_set("string8")));
        System.out.println("clear()");
        s.clear();
        s.print();
    }
}
